package it.irondev.appturismo.dao;

import it.irondev.appturismo.dao.example.MediaExample;
import it.irondev.appturismo.dao.provider.MediaSqlProvider;
import it.irondev.appturismo.entity.Media;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface MediaMapper {
    @SelectProvider(type=MediaSqlProvider.class, method="countByExample")
    int countByExample(MediaExample example);

    @DeleteProvider(type=MediaSqlProvider.class, method="deleteByExample")
    int deleteByExample(MediaExample example);

    @Delete({
        "delete from Media",
        "where idMedia = #{idmedia,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer idmedia);

    @Insert({
        "insert into Media (idMedia, url, ",
        "type, idGallery, ",
        "mediaType, ordineweb)",
        "values (#{idmedia,jdbcType=INTEGER}, #{url,jdbcType=VARCHAR}, ",
        "#{type,jdbcType=VARCHAR}, #{idgallery,jdbcType=INTEGER}, ",
        "#{mediatype,jdbcType=INTEGER}, #{ordineweb,jdbcType=INTEGER})"
    })
	@Options(useGeneratedKeys = true, keyProperty="idmedia")
    int insert(Media record);

    @InsertProvider(type=MediaSqlProvider.class, method="insertSelective")
    int insertSelective(Media record);

    @SelectProvider(type=MediaSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="idMedia", property="idmedia", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
        @Result(column="type", property="type", jdbcType=JdbcType.VARCHAR),
        @Result(column="idGallery", property="idgallery", jdbcType=JdbcType.INTEGER),
        @Result(column="mediaType", property="mediatype", jdbcType=JdbcType.INTEGER),
        @Result(column="ordineweb", property="ordineweb", jdbcType=JdbcType.INTEGER)
    })
    List<Media> selectByExample(MediaExample example);

    @Select({
        "select",
        "idMedia, url, type, idGallery, mediaType, ordineweb",
        "from Media",
        "where idMedia = #{idmedia,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="idMedia", property="idmedia", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
        @Result(column="type", property="type", jdbcType=JdbcType.VARCHAR),
        @Result(column="idGallery", property="idgallery", jdbcType=JdbcType.INTEGER),
        @Result(column="mediaType", property="mediatype", jdbcType=JdbcType.INTEGER),
        @Result(column="ordineweb", property="ordineweb", jdbcType=JdbcType.INTEGER)
    })
    Media selectByPrimaryKey(Integer idmedia);
    
    @Select({
        "select",
        "idMedia, url, type, idGallery, mediaType, ordineweb",
        "from Media",
        "where idGallery = #{idGallery,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="idMedia", property="idmedia", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
        @Result(column="type", property="type", jdbcType=JdbcType.VARCHAR),
        @Result(column="idGallery", property="idgallery", jdbcType=JdbcType.INTEGER),
        @Result(column="mediaType", property="mediatype", jdbcType=JdbcType.INTEGER),
        @Result(column="ordineweb", property="ordineweb", jdbcType=JdbcType.INTEGER)
    })
    List<Media> selectByGalleryId(Integer idGallery);    

    @UpdateProvider(type=MediaSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Media record, @Param("example") MediaExample example);

    @UpdateProvider(type=MediaSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Media record, @Param("example") MediaExample example);

    @UpdateProvider(type=MediaSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Media record);

    @Update({
        "update Media",
        "set url = #{url,jdbcType=VARCHAR},",
          "type = #{type,jdbcType=VARCHAR},",
          "idGallery = #{idgallery,jdbcType=INTEGER},",
          "mediaType = #{mediatype,jdbcType=INTEGER},",
          "ordineweb = #{ordineweb,jdbcType=INTEGER}",
        "where idMedia = #{idmedia,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Media record);
}